% corr3dscan.m
% created 05/02/2013
% Crown copyright
%
% Description: Returns correltation coefficient between two matrices
%
% @author Kevin O'Holleran <kevin.o-holleran@npl.co.uk>
%
% @param A - matrix
% @param B - matrix
% @param cx - correlation scan length in x axis
%
% @return result - double
function [ result ] = corr3dscan(A,B,cx,cy,cz)

[xn,yn,zn] = size(A);
result = zeros(cx,cy,cz);
x0 = round(cx/2);
y0 = round(cy/2);
z0 = round(cz/2);
As = A(x0:(xn-x0),y0:(yn-y0),z0:(zn-z0));
count = 0;
for i = 1:cx
    xi = round(x0-cx/2+i);
    for j = 1:cy
        yj = round(y0-cy/2+j);
        for k = 1:cz
            zk = round(z0-cz/2+k);
            Bs = B(xi:(xi+xn-cx),yj:(yj+yn-cy),zk:(zk+zn-cz));
            result(i,j,k) = corr2d(As,Bs);
            count = count+1;
        end
    end
    count/(cx*cy*cz)
end

end

